package View;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import presenter.Driver;

public class LoginScreen {

	private JFrame frame;
	private JTextField userText;
	private JTextField passText;
	private String[] roles;
	private JComboBox roleSelector;
	
	public LoginScreen()
	{
		initialize();
	}
	
	/**
	 * Closes the loginscreen window
	 */
	public void dispose()
	{
		frame.dispose();
	}

	/**
	 * Initializes the contents of the frame.
	 */
	public void initialize() 
	{
		frame = new JFrame("Login");
		frame.setBounds(MainWindow.XCENTER - 150, MainWindow.YCENTER - 75, 300, 150);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		frame.setLayout(new GridLayout(4, 2));
		Color myColor = new Color(200, 200, 200);
		frame.setBackground(myColor);;
		
		JLabel userID = new JLabel("  UserId:");
		JLabel passW = new JLabel("  Password:");
		JLabel drop = new JLabel("  Please select your role:");
		userText = new JTextField(15);
		passText = new JTextField(15);
		
		JButton loginButton = new JButton("Login");
		loginButton.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent e) 
			{
				Driver.myOfficePresenter.login(userText.getText(), passText.getText(), roleSelector.getSelectedIndex());
			}
		});
		
		JButton forgotButton = new JButton("Forgot Password?");
		roles = new String[4];
		roles[0] = "Patient";
		roles[1] = "Nurse";
		roles[2] = "System Administrator";
		roles[3] = "Doctor";
		roleSelector = new JComboBox(roles);
		
		frame.add(userID);
		frame.add(userText);
		frame.add(passW);
		frame.add(passText);
		frame.add(drop);
		frame.add(roleSelector);	
		frame.add(loginButton);
		frame.add(forgotButton);  
		
		frame.setVisible(true);
	}	
	
}	
	